<admintpl file="header" />
<style>
/* .qlistbox, table { */
/* 	overflow-y: scroll; */
/* } */

.qlisthead {
	padding: 0 0 10px 0;
}

.trsel {
	background-color: #DFEBF2;
}
.q_content{
	display:block;
}
.q_options{
	display:block;
}
.q_item{
	border:1px solid #ccc;
	padding:10px;
	margin-top:10px;
}
.q_options{
	padding:10px 0 0 0;
}
.q_options li{
	list-style-type: none;
}
.sortable{
}
.q_item_container{
	background-color: #eee;
}
</style>
</head>
<body>
	<div class="row-fluid">
		<div class="span4 wrap">
			<div class="qlistbar well">
				使用方法：右侧进行考题选择，左侧对选中的试题进行拖动排序，并点击确认完成选题操作。
				<br /><button class="btn btn-primary" type="button" onclick="sel_ok()">选择完成，确认</button>
			</div>
			<div class="qlistbox">
				<div class="qlisthead">
					<b>{$question_types[$paper_type]}（共计<span id="ques_sel_count">0</span>题）</b>
				</div>
				<div class="qlistbody sortable">

				</div>
			</div>
		</div>
		<div class="span8 wrap js-check-wrap">
			<form class="well form-search" method="post"
				action="{:U('Questions/queslist')}">
				分类： 
			<select name="term_id" style="width: 120px;">
				<option value='0'>全部</option>{$taxonomys}
			</select> &nbsp;&nbsp;
			<select name="level_id" style="width: 120px;">
				<option value='0'>全部</option>
				
			</select> &nbsp;&nbsp;
			试题ID： <input type="text" name="id" style="width: 100px;"
					value="{$id}" placeholder="请输入试题ID"> 题干： <input type="text"
					name="keyword" style="width: 100px;" value="{$keyword}"
					placeholder="请输入题干"> <input type="submit"
					class="btn btn-primary" value="搜索" />
			</form>
			<form class="js-ajax-form" action="" method="post">
				<table id="table1"
					class="table table-hover table-bordered table-list">
					<thead>
						<tr>
							<th width="15"></th>
							<notempty name="term">
							<th width="50">排序</th>
							</notempty>
							<th width="50">ID</th>
							<th width="100">试题分类</th>
							<th width="160">题干描述</th>
							<th width="100">试题难度</th>
						</tr>
					</thead>
					<foreach name="posts" item="vo">
					<tr>
						<td><input type="checkbox" class="js-check"
							data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
							value="{$vo.id}" title="ID:{$vo.id}"></td>
						<notempty name="term">
						<td><input name="listorders[{$vo.tid}]"
							class="input input-order" type="text" size="5"
							value="{$vo.listorder}"></td>
						</notempty>
						<td name="td1"><b>{$vo.id}</b></td>
						<td name="td2">{$question_types[$vo['ques_type']]}</td>
						<td name="td3">{$vo.ques_content}</td>
						<td name="td4">{$question_level[$vo['ques_level']]}</td>
					</tr>
					</foreach>
					<tfoot>
						<tr>
							<th width="15"></th>
							<notempty name="term">
							<th width="50">排序</th>
							</notempty>
							<th width="50">ID</th>
							<th width="100">试题分类</th>
							<th width="160">题干描述</th>
							<th width="100">试题难度</th>
						</tr>
					</tfoot>
				</table>
				<div class="pagination">{$page}</div>
			</form>
		</div>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script src="__PUBLIC__/js/cookie.js"></script>
	<SCRIPT LANGUAGE="JavaScript">
	var current_ques_ids_arr=new Array();
	var current_ques_ids="";
	var chk_ques_ids="";
	function sel_ok(){
		current_ques_ids_arr=[];
		$('.q_item').each(function(index){
			current_ques_ids_arr.push($(this).data('id'));
		});
		current_ques_ids=current_ques_ids_arr.join(',');
		//alert(current_ques_ids);
		$.cookie('current_ques_ids{$paper_type}',current_ques_ids);
		window.parent.setqueslist({$paper_type},current_ques_ids);
	}
	$(function() {
		init_ques_list();
		$("tbody tr").click(function() {
			$(this).toggleClass('trsel');
			var chk = $(this).find(":checkbox");
			$(this).find(":checkbox").attr("checked",!$(chk).attr("checked"));

			show_ques_list();
		});
		
		function show_ques_list(){
			$('.qlistbody').empty();
			current_ques_ids_arr=[];
			var ques_count=0;
			var nIndex=1;
			 $('#table1 tr').each(function(index){
				 var chk = $(this).find(":checkbox");
					if($(chk).attr("checked")){
						var td1=$(this).find("td[name='td1']").text();
						var td2=$(this).find("td[name='td2']").text();
						var td3=$(this).find("td[name='td3']").text();
						var td4=$(this).find("td[name='td4']").text();
						var div=["<div class=\"q_item_container\">",
						"<div class=\"q_item\" data-id=\"",td1,"\">",
						"<div class=\"q_content\">",nIndex++,"，编号",td1,"-",td4,"-",td2,"<br />",td3,"</div>",
// 						"<div class=\"q_options\">",td3,"</div>",
						"</div>",
						"</div>"].join("");
						current_ques_ids_arr.push(td1);
						$('.qlistbody').append(div);
						ques_count++;
					}
			 });
			 $("#ques_sel_count").text(ques_count);
			 //alert(current_ques_ids_arr.join(','));			
		}
		
		function init_ques_list(){
			$('.qlistbody').empty();
			current_ques_ids=$.cookie('current_ques_ids{$paper_type}');
			if(current_ques_ids==null)return;
			current_ques_ids_arr=current_ques_ids.split(',');
			var ques_count=0;
			var nIndex=1;
			 $('#table1 tr').each(function(index){
				var chk = $(this).find(":checkbox");
				if(current_ques_ids_arr.indexOf($(chk).val())>-1){
					 $(this).toggleClass('trsel');
					$(chk).attr("checked",true);
					var td1=$(this).find("td[name='td1']").text();
					var td2=$(this).find("td[name='td2']").text();
					var td3=$(this).find("td[name='td3']").text();
					var td4=$(this).find("td[name='td4']").text();
					var div=["<div class=\"q_item_container\">",
					"<div class=\"q_item\" data-id=\"",td1,"\">",
					"<div class=\"q_content\">",nIndex++,"，编号",td1,"-",td4,"-",td2,"<br />",td3,"</div>",
					//"<div class=\"q_options\">",td3,"</div>",
					"</div>",
					"</div>"].join("");
					current_ques_ids_arr.push(td1);
					$('.qlistbody').append(div);
					ques_count++;
				}
			 });
			 $("#ques_sel_count").text(ques_count);
			 //alert(current_ques_ids_arr.join(','));			
		}
	});
	</SCRIPT>

	<script>
		$(".sortable").sortable({
	      placeholder: "ui-state-highlight"
	    });
		$(".sortable").disableSelection();
		
		function refersh_window() {
			var refersh_time = getCookie('refersh_time');
			if (refersh_time == 1) {
				window.location = "{:U('Questions/queslist',$formget)}";
			}
		}
		setInterval(function() {
			refersh_window();
		}, 2000);
		$(function() {
			setCookie("refersh_time", 0);
			Wind.use('validate', 'ajaxForm', 'artDialog', function() {
				var form = $('form.js-ajax-forms');
				//ie处理placeholder提交问题
				if ($.browser && $.browser.msie) {
					form.find('[placeholder]').each(function() {
						var input = $(this);
						if (input.val() == input.attr('placeholder')) {
							input.val('');
						}
					});
				}
				var formloading = false;
				//表单验证开始
				form.validate({
					//是否在获取焦点时验证
					onfocusout : false,
					//是否在敲击键盘时验证
					onkeyup : false,
					//当鼠标掉级时验证
					onclick : false,
					//验证错误
					showErrors : function(errorMap, errorArr) {
						//errorMap {'name':'错误信息'}
						//errorArr [{'message':'错误信息',element:({})}]
						try {
							$(errorArr[0].element).focus();
							art.dialog({
								id : 'error',
								icon : 'error',
								lock : true,
								fixed : true,
								background : "#CCCCCC",
								opacity : 0,
								content : errorArr[0].message,
								cancelVal : '确定',
								cancel : function() {
									$(errorArr[0].element).focus();
								}
							});
						} catch (err) {
						}
					},
					//验证规则
					rules : {
						paper_name : {
							required : true
						},
						paper_type : {
							required : true
						},
						paper_term : {
							required : true
						},
						paper_score : {
							required : true
						},
						paper_pass_score : {
							required : true
						},
//		 				opt : {
//		 					required : $('#ques_type').val()==1||$('#ques_type').val()==4
//		 				},
//		 				'opts[]' : {
//		 					required : $('#ques_type').val()==2
//		 				},
						
					},
					//验证未通过提示消息
					messages : {
						ques_term : {
							required : '请选择考题分类'
						},
						ques_type : {
							required : '请选择题型'
						},
						ques_score : {
							required : '请填写试题分数'
						},
						ques_content : {
							required : '请填写题干',
							editorcontent : '内容不能为空'
						}			
						
					},
//		 			errorPlacement: function (error, element) { //指定错误信息位置
//		 				if (element.is(':radio') || element.is(':checkbox')) {
//		 					var eid = element.attr('name');
//		 					error.appendTo(element.parent());
//		 				} else {
//		 					error.insertAfter(element);
//		 				}
//		 			},
					//给未通过验证的元素加效果,闪烁等
					highlight : false,
					//是否在获取焦点时验证
					onfocusout : false,
					//验证通过，提交表单
					submitHandler : function(forms) {
						if (formloading)
							return;
						$(forms).ajaxSubmit({
							url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
							dataType : 'json',
							beforeSubmit : function(arr, $form, options) {
								formloading = true;
							},
							success : function(data, statusText, xhr, $form) {
								formloading = false;
								if (data.status) {
									setCookie("refersh_time", 1);
									//添加成功
									Wind.use("artDialog", function() {
										art.dialog({
											id : "succeed",
											icon : "succeed",
											fixed : true,
											lock : true,
											background : "#CCCCCC",
											opacity : 0,
											content : data.info,
											button : [ {
												name : '继续添加？',
												callback : function() {
													reloadPage(window);
													return true;
												},
												focus : true
											}, {
												name : '返回列表页',
												callback : function() {
													location = "{:U('Questions/index')}";
													return true;
												}
											} ]
										});
									});
								} else {
									artdialog_alert(data.info);
								}
							}
						});
					}
				});
			});
		});
	</script>
</body>
</html>